package com.youweather.sgg.test;

import static org.junit.Assert.*;

import java.io.InputStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;

import android.database.sqlite.SQLiteDatabase;
import android.test.ActivityInstrumentationTestCase2;

import com.youweather.sgg.City;
import com.youweather.sgg.DatabaseHelper;
import com.youweather.sgg.ICities;


@RunWith(JMock.class)
public class testCity{

	// create the context for the mock object
	Mockery context = new JUnit4Mockery();
    final ICities c = context.mock(ICities.class);
	City ct = new City();
	DatabaseHelper databaseHelper = DatabaseHelper.getInstance(ct.getApplicationContext());  //creo l'helper per aprire il DB
    SQLiteDatabase db = databaseHelper.getWritableDatabase();  //apro il DB sia in lettura che in scrittura
   
	@Before
	protected void setUp() throws Exception {
		
	}
 	@Test
    public void testCaricamentoFileContenenteLeCittaNelDatabaseSQLiteInteroTramitejMock(){
        
        //settiamo l'expectation per l'oggetto mock
        context.checking(new Expectations(){{
			  InputStream file = null;
			//l'oggetto mock deve chiamare load una volta
             one(c).load(db, file); will(returnValue(true));
         }});
        
      assertEquals(ct.loading(db),true);
      context.assertIsSatisfied();
        
    }
}
